tiejingshiMgr = {}
QMPlugin = tiejingshiMgr
function tiejingshiMgr.init()
    if boot.platform == 1 then
        tiejingshiMgr.paraConfig = {
            ["铁"] = {  509,491,912,1749,"93BED3-303030","-25|-23|93BED3,-23|32|93BED3,25|-123|FBFADB,-6|-106|B58463,-51|-101|B67163,-37|-74|A7655C,-23|90|93BED3",0,0.9},
            ["晶石"] = {   54,468,909,1807,"93BED3-303030","18|-46|93BED3,10|-81|93BED3,30|-175|FDC0E1,3|-201|F3BBD2,-19|-190|DF707D,-33|-170|F09B8A,-10|-142|ED9369,9|-126|EDA69D,17|37|93BED3",2,0.9},
            ["梦幻币"] = { 148,475,912,1775,"2799D6-303030","28|0|EEFFFF,9|-20|50CAFA,-14|4|49CDFA,5|22|49BFF2,21|0|44B7F1,-2|-9|3AC2FF,11|8|67E3FF",2,0.95},
            ["购买"] = { 157,1381,322,1678,"515CDB-303030","-1|-114|505BDB,-6|101|4E59D7,12|-47|D0EEFF,-18|-47|CFEEFF,-19|-27|CFEEFF,2|14|D0EEFF,7|18|D0EEFF,-5|45|CFEEFF,-20|43|C9E7FB",2,0.95},
            ["装备打造"] = { 22,62,957,475,"182971-303030","-1|-72|182971,-27|-59|182971,-28|-18|182971,-27|12|182971,1|47|192B73,-10|55|182971,-16|55|182971,-15|135|3D5CA8,-4|126|3C5BA7",2,0.95},
        }
    else
    end
end

local function findTie()
    local para = tiejingshiMgr.paraConfig["铁"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function findJingshi()
    local para = tiejingshiMgr.paraConfig["晶石"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function findIcon()
    local para = tiejingshiMgr.paraConfig["梦幻币"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function buy()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = tiejingshiMgr.paraConfig["购买"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function dazao()
    local para = tiejingshiMgr.paraConfig["装备打造"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end


function tiejingshiMgr.execTask()
    mlog.info("抢铁")
    local count = 1
    while true do
        game.drag(851,1113,215,1110,200)
        game.delay(500)
        count = 2 - count
        if count == 1 then
            mlog.info("抢购铁")
            local tie,x,y = findTie()
            if tie then
                game.tap(x, y)
                game.delay(200)
            end
        else
            mlog.info("抢购晶石")
            local jingshi,x,y = findJingshi()
            if jingshi then
                game.tap(x, y)
                game.delay(200)
            end
        end

        local icon,x,y = findIcon()
        if icon then
            mlog.info("findIcon")
            game.tap(x, y)
            game.delay(800)
            local buybtn,x,y = buy()
            if buybtn then
                mlog.info("buybtn")
                game.tap(x, y)
                game.delay(500)
            end
        end
        local dazaoBtn,x,y = dazao()
        if dazaoBtn then
            game.tap(x, y)
            game.delay(200)
        end

        count = count + 1
    end
end

